package com.briup.app01.web.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.briup.app01.bean.Article;
import com.briup.app01.service.IArticleservice;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;


@RequestMapping("/article")
@Api(description="article栏目描述")
@RestController
public class ArticleController {
	@Autowired
	private IArticleservice iArticleservice;

//	@RequestMapping("/save")
//	public String save(Article article) {
//		iArticleservice.save(article);
//		return "保存成功";
//
//	}
	@ApiOperation("查询所有栏目信息")
	@GetMapping("/findAll")
	public List<Article> findAll() {
		return iArticleservice.findAll();
	}
	@ApiOperation("通过id查询栏目信息")
	@GetMapping("/findAllById")
	public Article findAllById(Long id) {
		return iArticleservice.findById(id);
	}
	@ApiOperation("通过id删除信息")
	@DeleteMapping("/deleteById")
	public String deleteById(Long id) {
		if (iArticleservice.delete(id)) {
			return "删除成功";
		} else {
			return "删除失败";
		}

	}

//	@GetMapping("/updateById")
//	public String updateById(Article article) {
//		if (iArticleservice.update(article)) {
//			return "更新成功";
//		} else {
//			return "更新失败";
//		}
//	}
	@ApiOperation(value="更新或者添加信息",notes="如果id为空为保存，否则为更新")
	@PostMapping("/saveOrUpdate")
	public String saveOrUpdate(Article article) {
		iArticleservice.saveOrUpdate(article);
				
		return "保存成功";}
}

